package com.hqyj.repertory.service.impl;

import com.hqyj.purchase.model.PurchaseInfo;
import com.hqyj.repertory.mapper.InRepertoryMapper;
import com.hqyj.repertory.model.InRepertory;
import com.hqyj.repertory.service.InRepertoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class InRepertoryServiceIml implements InRepertoryService {
    @Autowired
    private InRepertoryMapper inRepertoryMapper;
    @Override
    public ArrayList<InRepertory> queryAllInRepertory() {
        return inRepertoryMapper.queryAllInRepertory();
    }

    @Override
    public InRepertory queryInRepertoryById(int id) {
        return inRepertoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateInRepertory(InRepertory inRepertory) {
        inRepertoryMapper.updateByPrimaryKeySelective(inRepertory);
    }

    @Override
    public int addInRepertory(PurchaseInfo purchaseInfo) {
        InRepertory inRepertory = new InRepertory();
        inRepertory.setInRepertoryId(purchaseInfo.getId());
        inRepertory.setInRepertoryDate(purchaseInfo.getPurchaseDate());
        inRepertory.setProvider(purchaseInfo.getProvider());
        inRepertory.setProductMaterialsName(purchaseInfo.getTradeName());
        inRepertory.setInRepertoryNumber(purchaseInfo.getPurchaseNum());
        inRepertory.setType("原料");
        int rows = inRepertoryMapper.insert(inRepertory);
        return rows;
    }
}

